package com.haoshuang.zhouzhoubang.ui.activity

import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import com.haoshuang.zhouzhoubang.databinding.ActivityWarrantyBinding
import com.haoshuang.zhouzhoubang.ui.adapter.ZbAdapter
import com.haoshuang.zhouzhoubang.ui.vm.WarrantyViewModel
import com.mufeng.libs.base.BaseActivity
import com.mufeng.libs.state.observeState
import com.mufeng.libs.utils.toast
import com.mufeng.libs.utils.view.click


/**
 *服务质保期
 */
class WarrantyActivity : BaseActivity<WarrantyViewModel, ActivityWarrantyBinding>() {

    override fun initView(savedInstanceState: Bundle?) {
        binding.appBar.ivBack.click { finish() }
        binding.appBar.tvTitle.text = "服务质保期"
    }

    lateinit var adpater: ZbAdapter
    var list = arrayListOf<String>()
    override fun initData() {
        var ids = intent.getIntExtra("ids", 0)
        vm.getData("id" to ids)
        adpater = ZbAdapter(list)
        binding.rvList.layoutManager=LinearLayoutManager(this)
        binding.rvList.adapter=adpater
    }


    override fun startObserve() {
        vm.getData.observeState(this) {
            onLoading { showLoading() }
            onError { code, msg ->
                dismissLoading()
                toast(msg)
            }
            onSuccess {

                dismissLoading()
                if (it != null) {
                    list.addAll(it)
                    adpater.notifyDataSetChanged()
                }
                // binding.webView.text=it[1]
            }
        }
    }

}